package e.odbo.data.service.id.impl;

import com.openbravo.data.basic.BasicException;
import e.odbo.data.sample.tableid.TableIdGeneratorDAO;
import e.odbo.data.service.id.I_NumberIdGeneratorService;
import e.odbo.data.service.lock.I_LockService;

public class OdbOIdGeneratorService implements I_NumberIdGeneratorService {

    TableIdGeneratorDAO tableIdGeneratorDAO;

    I_LockService lockService;

    public OdbOIdGeneratorService(TableIdGeneratorDAO tableIdGeneratorDAO, I_LockService lockService) {
        this.tableIdGeneratorDAO = tableIdGeneratorDAO;
        this.lockService = lockService;
    }

    @Override
    public int next_int(String tableName) throws BasicException {
        int ret;
        lockService.lock(tableName);
        ret=tableIdGeneratorDAO.next_id_int(tableName);
        lockService.unLock(tableName);
        return ret;
    }

    @Override
    public long next_long(String tableName) throws BasicException {
        long ret;
        lockService.lock(tableName);
        ret=tableIdGeneratorDAO.next_id_int(tableName);
        lockService.unLock(tableName);
        return ret;
    }
}
